/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package com.sambi.mvc.view;

import com.sambi.mvc.FormControl;
import com.sambi.mvc.TextField;
import com.sambi.mvc.controller.InvoicesSearchController;
import com.sambi.mvc.model.InvoicesSearchModel;
import java.beans.PropertyChangeEvent;
import javax.swing.JButton;
import javax.swing.JTextField;

/**
 *
 * @author Habib
 */
public class Frame extends javax.swing.JFrame implements AbstractFrame {

    InvoicesSearchModel invoicesSearchModel;
    InvoicesSearchController controller;

    /**
     * Creates new form Frame
     */
    public Frame() {
        initComponents();
        invoicesSearchModel = new InvoicesSearchModel();
        controller = new InvoicesSearchController(this);
        controller.addModel(invoicesSearchModel);
    }

    public JTextField getjTCustomerId() {
        return jTCustomerId;
    }

    public JTextField getjTCustomerName() {
        return jTCustomerName;
    }

    public TextField getjTNbInvoices() {
        return jTNbInvoices;
    }

    

    public JButton getjBCancel() {
        return jBCancel;
    }

    public JButton getjBSearch() {
        return jBSearch;
    }
    
    

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jBSearch = new javax.swing.JButton();
        jBCancel = new javax.swing.JButton();
        jTCustomerId = new com.sambi.mvc.TextField();
        jTCustomerName = new com.sambi.mvc.TextField();
        jTNbInvoices = new com.sambi.mvc.TextField();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        jLabel1.setText("Kode Number");

        jLabel2.setText("Kode Name");

        jLabel3.setText("Ga tau apa");

        jBSearch.setText("Suchen");

        jBCancel.setText("Abbrechen");

        jTCustomerName.setPosisi(1);

        jTNbInvoices.setPosisi(2);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(112, 112, 112)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jLabel3, javax.swing.GroupLayout.PREFERRED_SIZE, 64, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addGroup(layout.createSequentialGroup()
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jBSearch)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jBCancel))
                            .addGroup(layout.createSequentialGroup()
                                .addGap(10, 10, 10)
                                .addComponent(jTNbInvoices, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))))
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                            .addComponent(jLabel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(jLabel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                        .addGap(10, 10, 10)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jTCustomerId, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(jTCustomerName, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))))
                .addContainerGap(62, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(68, 68, 68)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1)
                    .addComponent(jTCustomerId, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jTCustomerName, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel2))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel3)
                    .addComponent(jTNbInvoices, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(32, 32, 32)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jBSearch)
                    .addComponent(jBCancel))
                .addContainerGap(96, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jBCancel;
    private javax.swing.JButton jBSearch;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private com.sambi.mvc.TextField jTCustomerId;
    private com.sambi.mvc.TextField jTCustomerName;
    private com.sambi.mvc.TextField jTNbInvoices;
    // End of variables declaration//GEN-END:variables

    @Override
    public void modelPropertyChange(PropertyChangeEvent event) {
        
        for(String s:InvoicesSearchController.property){
            if(s.equalsIgnoreCase(event.getPropertyName())){
                String newStringValue = event.getNewValue().toString();
                System.out.println(event.getPropertyName());
                if (!FormControl.getCurrentText().getText().equals(newStringValue)) {
                    FormControl.getCurrentText().setText(newStringValue);
                }
                break;
            }
        }

//        switch (event.getPropertyName()) {
//            case InvoicesSearchController.CUSTOMERID_PROPERTY: {
//                String newStringValue = event.getNewValue().toString();
//                if (!jTCustomerId.getText().equals(newStringValue)) {
//                    jTCustomerId.setText(newStringValue);
//                }
//                break;
//            }
//            case InvoicesSearchController.CUSTOMERNAME_PROPERTY: {
//                String newStringValue = event.getNewValue().toString();
//                if (!jTCustomerName.getText().equals(newStringValue)) {
//                    jTCustomerName.setText(newStringValue);
//                }
//                break;
//            }
//            case InvoicesSearchController.NBINVOICES_PROPERTY: {
//                int newIntegerValue = (Integer) event.getNewValue();
//                if (Integer.parseInt(jTNbInvoices.getText()) != newIntegerValue) {
//                    jTNbInvoices.setText(newIntegerValue + "");
//                }
//                break;
//            }
//            default:
//                break;
//        }
    }
}
